package com.evs.basic.service.impl;

import com.evs.basic.mapper.BaseMapper;
import com.evs.basic.query.BaseQuery;
import com.evs.basic.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.loadAll();
    }

    @Override
    public List<T> queryPage(BaseQuery query) {
        return baseMapper.queryData(query);
    }

    @Override
    public Long queryCount(BaseQuery query) {
        return baseMapper.queryCount(query);
    }

    @Override
    @Transactional
    public void batchDelete(List<Long> ids) {
        baseMapper.bulkRemove(ids);
    }
}
